import { $t } from '@vben/locales';

/**
 * @author Buke
 * @description 表单hook
 * @param options 表单配置
 */
export const useFormConfigHook = <T extends Record<string, any>>(
  options: T,
) => {
  const { labelkey, schema, ...rest } = options;
  // 表单默认配置
  const defaultConfig = {
    layout: 'vertical',
    showDefaultActions: false, // 不显示操作按钮
  };
  // 处理表单列配置
  const newSchema = schema.map((item: any) => {
    return {
      ...item,
      label: $t(`${labelkey}.${item.fieldName}`),
      component: item.component || 'Input',
    };
  });
  // 合并默认配置和传入的配置
  const newFormConfig = {
    ...defaultConfig,
    ...rest,
    schema: newSchema,
  } as unknown as T;

  return {
    newFormConfig,
  };
};
